<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input clearable @keyup.enter.native="handleFilter" style="width: 150px;" class="filter-item" placeholder="请输入卡号" v-model="listQuery.cardNo">
      </el-input>
      <el-date-picker
        v-model="value"
        type="datetimerange"
        align="right"
        clearable
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        format="yyyy-MM-dd HH:mm:ss"
        value-format="yyyy-MM-dd HH:mm:ss"
        @change="getTime"
        :default-time="['12:00:00', '08:00:00']">
      </el-date-picker>
      <el-button size="small" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>
    <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label='巡检人'>
        <template slot-scope="scope">
          {{scope.row.adminName}}
        </template>
      </el-table-column>
      <el-table-column label="门牌卡号" align="center">
        <template slot-scope="scope">
          {{scope.row.cardNo}}
        </template>
      </el-table-column>
      <el-table-column label="用户住址" align="center">
        <template slot-scope="scope">
          {{scope.row.address}}
        </template>
      </el-table-column>
      <el-table-column label="设备名称" align="center">
        <template slot-scope="scope">
          {{scope.row.deviceName}}
        </template>
      </el-table-column>
      <el-table-column label="投放类型" align="center">
        <template slot-scope="scope">
          {{scope.row.deviceTypeName}}
        </template>
      </el-table-column>
      <el-table-column label="巡检状态" align="center">
        <template slot-scope="scope">
          {{scope.row.stateName}}
        </template>
      </el-table-column>
      <el-table-column label="巡检方式" align="center">
        <template slot-scope="scope">
          {{scope.row.inspectionTypeName}}
        </template>
      </el-table-column>
      <el-table-column label="巡检时间" align="center">
        <template slot-scope="scope">
          {{scope.row.inspectionTime}}
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page.sync="listQuery.page" :page-sizes="[10,20,30,50]"
                     :page-size="listQuery.size" layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </div>
    <!--分页END-->
  </div>
</template>

<script>
  import { getList } from '@/api/device/insRecord'

  export default {
    data() {
      return {
        list: null,
        listLoading: true,
        total: null,
        listQuery: {
          id: undefined,
          cardNo: '',
          timeStart: '',
          timeEnd: ''
        },
        value: ''
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      // 获取列表
      fetchData() {
        this.listLoading = true
        getList(this.listQuery).then(response => {
          this.list = response.data.content
          this.total = response.data.totalElements
          this.listQuery.size = response.data.size
          this.listLoading = false
        })
      },
      handleFilter() {
        this.fetchData()
      },
      getTime(date) {
        this.listQuery.timeStart = date[0]
        this.listQuery.timeEnd = date[1]
      },
      handleSizeChange(val) {
        this.listQuery.size = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.listQuery.page = val
        this.fetchData()
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .filter-container{
    padding-bottom: 10px;
  }
</style>
